INITIALINC = 1.
MININC = 1.e-5 
MAXINC = 1.
MAXNUMINC = 1000
STABILIZATIONMAGNITUDE = 4.e-7
COLOR_RED        = '#FF0000'
COLOR_WHINE      = '#950000'
COLOR_BLUE       = '#0000FF'
COLOR_DARK_BLUE  = '#0000B3'
COLOR_BLACK      = '#000000'
ADAPTIVEDAMPINGRATIO = 0.05
from abaqusConstants import *
def static_step( model, name, previous, damping=False,
                 maxNumInc = None,
                 initialInc = None,
                 minInc = None,
                 maxInc = None,
                 stabilizationMagnitude = None,
                 adaptiveDampingRatio = None):
    if initialInc == None:
        initialInc = INITIALINC
    if maxNumInc == None:
        maxNumInc = MAXNUMINC
    if minInc == None:
        minInc = MININC
    if maxInc == None:
        maxInc = MAXINC
    if stabilizationMagnitude == None:
        stabilizationMagnitude = STABILIZATIONMAGNITUDE
    if adaptiveDampingRatio == None or adaptiveDampingRatio == True:
        adaptiveDampingRatio = ADAPTIVEDAMPINGRATIO
    elif adaptiveDampingRatio == 0  or adaptiveDampingRatio == False:
        adaptiveDampingRatio = 0
    # consistency checks
    if initialInc > maxInc:
        initialInc = maxInc
    # 
    if not damping:
        model.StaticStep( name=name,
                          previous=previous,
                          description = '',
                          timePeriod = 1.,
                          nlgeom=ON,
                          stabilizationMethod = NONE,
                          timeIncrementationMethod = AUTOMATIC,
                          maxNumInc = maxNumInc,
                          initialInc = initialInc,
                          minInc = minInc,
                          maxInc = maxInc,
                          matrixSolver = DIRECT,
                          matrixStorage = SOLVER_DEFAULT,
                          amplitude = STEP, # RAMP or STEP
                          extrapolation = PARABOLIC,
                          solutionTechnique = FULL_NEWTON,
                          adaptiveDampingRatio = adaptiveDampingRatio,
                          continueDampingFactors = OFF,
                        )
    elif damping:
        model.StaticStep( name=name,
                          previous=previous,
                          description = '',
                          timePeriod = 1.,
                          nlgeom=ON,
                          stabilizationMethod = DAMPING_FACTOR,
                          stabilizationMagnitude = stabilizationMagnitude,
                          timeIncrementationMethod = AUTOMATIC,
                          maxNumInc = maxNumInc,
                          initialInc = initialInc,
                          minInc = minInc,
                          maxInc = maxInc,
                          matrixSolver = DIRECT,
                          matrixStorage = SOLVER_DEFAULT,
                          amplitude = STEP, #RAMP
                          extrapolation = PARABOLIC,
                          solutionTechnique = FULL_NEWTON,
                          adaptiveDampingRatio = adaptiveDampingRatio,
                          continueDampingFactors = OFF,
                        )
def displacementBC( model, name, createStepName, region,
                    u1, u2, u3, ur1, ur2, ur3,
                    localCsys ):
    model.DisplacementBC( name=name,
                          createStepName=createStepName,
                          region = region,
                          u1=u1,
                          u2=u2,
                          u3=u3,
                          ur1=ur1,
                          ur2=ur2,
                          ur3=ur3,
                          amplitude = UNSET,
                          distributionType = UNIFORM,
                          fieldName = '',
                          localCsys = localCsys,
                          #buckleCase=BUCKLING_MODES
                        ) #NOT_APPLICABLE


def configure_session( session=None ):
    if session == None:
        import __main__
        session = __main__.session
    plot_names = session.xyDataObjects.keys()
    if not 'XYPlot-1' in session.xyPlots.keys():
        xyp = session.XYPlot('XYPlot-1')
    else:
        xyp = session.xyPlots['XYPlot-1']
    chartName = xyp.charts.keys()[0]
    chart = xyp.charts[chartName]
    tmp = session.xyDataObjects.keys()
    xy1 = session.xyDataObjects[ tmp[0] ]
    c1 = session.Curve(xyData=xy1)
    chart.setValues(curvesToPlot=(c1, ), )
    session.viewports['Viewport: 1'].setValues(displayedObject=xyp)
    #
    chart = session.charts['Chart-1']
    chart.minorAxis1GridStyle.setValues( show  = True   )
    chart.majorAxis1GridStyle.setValues( show  = True   )
    chart.majorAxis1GridStyle.setValues( style = DASHED )
    chart.minorAxis2GridStyle.setValues( show  = True   )
    chart.majorAxis2GridStyle.setValues( show  = True   )
    chart.majorAxis2GridStyle.setValues( style = DASHED )
    chart.gridArea.style.setValues( fill = False )
    chart.legend.setValues( show = False ) # necessary to update legend values
    chart.legend.setValues( show = True  )
    chart.legend.area.setValues( inset = True )
    chart.legend.area.setValues( originOffset=(0.,0.) )
    chart.legend.area.style.setValues( fill = True )
    chart.legend.textStyle.setValues(
            font='-*-arial narrow-medium-r-normal-*-*-480-*-*-p-*-*-*')
    for name in plot_names:
        c = session.Curve(xyData=session.xyDataObjects[name])
        chart = session.xyPlots['XYPlot-1'].charts['Chart-1']
        chart.setValues(curvesToPlot=(c,))
        chart.fitCurves( fitAxes1=True, fitAxes2=True )
        curve = session.charts['Chart-1'].curves[name]
        curve.curveOptions.setValues(showSymbol = ON)
        curve.curveOptions.setValues(symbolSize = SMALL)
        curve.lineStyle.setValues( thickness = 1.6,
                                   color     = COLOR_BLACK )
        curve.symbolStyle.setValues( size   = 5,
                                     color  = COLOR_BLACK,
                                     marker = HOLLOW_CIRCLE )
        ax = chart.axes1[0] 
        ay = chart.axes2[0]
        ax.labelStyle.setValues(
            font  = '-*-arial narrow-bold-r-normal-*-*-480-*-*-p-*-*-*',
            color = COLOR_BLACK )
        ax.titleStyle.setValues(
            font  = '-*-arial narrow-bold-r-normal-*-*-480-*-*-p-*-*-*',
            color = COLOR_BLACK )
        ay.labelStyle.setValues(
            font  = '-*-arial narrow-bold-r-normal-*-*-480-*-*-p-*-*-*',
            color = COLOR_BLACK )
        ay.titleStyle.setValues(
            font  = '-*-arial narrow-bold-r-normal-*-*-480-*-*-p-*-*-*',
            color = COLOR_BLACK)
        ax.setValues(tickPlacement=OUTSIDE)
        ax.axisData.setValues(
                               labelFormat=DECIMAL,
                               labelNumDigits = 0,
                               minorTickCount = 4,
                             )
        ay.setValues(tickPlacement=OUTSIDE)
        ay.axisData.setValues(
                               labelFormat=DECIMAL,
                               labelNumDigits = 0,
                             )
        if ax.axisData.title.find('ispl') > -1:
            ax.axisData.setValues( labelNumDigits = 1 )
        if name.find('circumference') > -1:
            ax.axisData.setValues(
                                   tickMode       = INCREMENT,
                                   tickIncrement  = 20,
                                   minorTickCount = 0,
                                   minAutoCompute = False,
                                   minValue       = -180,
                                   maxAutoCompute = False,
                                   maxValue       =  185,
                                 )
        #
        if name.find('FI_HSNFCCRT') > -1 or name.find('FI_HSNFTCRT') > -1\
        or name.find('FI_HSNMCCRT') > -1 or name.find('FI_HSNMTCRT') > -1:
            ay.axisData.setValues( labelNumDigits = 1,
                                   minAutoCompute = False,
                                   minValue       = 0,
                                   maxAutoCompute = False,
                                   maxValue       = 2 )
            curve.lineStyle.setValues(
                                   thickness = 1.6,
                                   color     = COLOR_WHINE )
            curve.curveOptions.setValues(showSymbol = OFF)
            ay.titleStyle.setValues( color = COLOR_WHINE )
            ay.labelStyle.setValues( color = COLOR_WHINE )
        #
        if name.find('MS_HSNFCCRT') > -1 or name.find('MS_HSNFTCRT') > -1\
        or name.find('MS_HSNMCCRT') > -1 or name.find('MS_HSNMTCRT') > -1\
        or name.find('MS_MAX')      > -1 or name.find('MS_MIN')      > -1:
            ay.axisData.setValues( labelNumDigits = 1,
                                   minAutoCompute = False,
                                   minValue       = -0.5,
                                   maxAutoCompute = False,
                                   maxValue       =  1.0   )
            curve.lineStyle.setValues(
                                   thickness = 1.6,
                                   color     = COLOR_DARK_BLUE )
            curve.curveOptions.setValues(showSymbol = OFF)
            ay.titleStyle.setValues( color = COLOR_DARK_BLUE )
            ay.labelStyle.setValues( color = COLOR_DARK_BLUE )

